package com.InsideGamer.SuperJailBreak;

import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;

public class BasicBlockListener extends BlockListener {
	private JailBreak plugin;
	
	public BasicBlockListener ( JailBreak pluginInstance )
	{
		plugin = pluginInstance;
	}
	
	public void onBlockBreak ( BlockBreakEvent event )
	{
		Player player = event.getPlayer();
		
		if ( event.getBlock().getTypeId() == 46 )
		{
			if ( !plugin.users.IsHidden ( player ) )
			{
				plugin.getServer().broadcastMessage ( player.getName() + " heeft een TNT blokje weggehaald." );
			}
		}
		
		Location loc1 = new Location (event.getPlayer().getWorld(), -19.0, 65.0, -380.0 );
		Location loc2 = new Location (event.getPlayer().getWorld(), -14.0, 65.0, -365.0 );
		Location locP = event.getBlock().getLocation();
		
		if ( locP.getX() >= loc1.getBlockX() && locP.getZ() >= loc1.getBlockZ() &&
			 locP.getX() <= loc2.getBlockX() && locP.getZ() <= loc2.getBlockZ() )
		{
			plugin.getServer().broadcastMessage ( player.getName() + " is aan het griefen in een beschermd gebied!" );
			event.setCancelled(true);
		}
	}
	
	public void onBlockPlace ( BlockPlaceEvent event )
	{
		Player player = event.getPlayer();
		int BlockID = event.getBlock().getTypeId();
		
		if ( BlockID == 46 )
		{
			if ( !plugin.users.IsHidden ( player ) )
			{
				plugin.getServer().broadcastMessage ( ChatColor.RED + player.getName() + " heeft TNT geplaatst." );
			}
		}
	}
}
